import { defineStore } from 'pinia'
import { ref } from 'vue'
import { loginAPI } from '@/apis/user'
import { useCartStore } from './cart'

export const useUserStore = defineStore('userStore', () => {
  // 分类列表
  const userInfo = ref({})

  // 获取分类信息
  const getUserInfo = async (data) => {
    const res = await loginAPI(data)
    console.log(res)
    userInfo.value = res.result
  }

  const cartStore = useCartStore()
  const removeUserInfo = () => {
    userInfo.value = {}
    cartStore.clearCart()
  }

  return {
    userInfo,
    getUserInfo,
    removeUserInfo
  }
}, {
  persist: true
})